//
// Created by Shao Wenhan on 2021/9/28.
//

#include "ConfigurableEventListener.h"
#include "MedianOfFixedLengthArray.h"

class TestMedianOfFixedLengthArray: public testing::Test{
public:
    MedianOfFixedLengthArray<int> medianOfFixedLengthWithOddEle;
    MedianOfFixedLengthArray<int> medianOfFixedLengthWithEvenEle;

    TestMedianOfFixedLengthArray() {
        medianOfFixedLengthWithOddEle.initialize({4, 9, 1, 8, 2});
        medianOfFixedLengthWithEvenEle.initialize({-1, 3, 6, 7});
    };
};

TEST_F(TestMedianOfFixedLengthArray, FindMedium)
{
    ASSERT_FLOAT_EQ(4, medianOfFixedLengthWithOddEle.getMedian());
    ASSERT_FLOAT_EQ(4.5, medianOfFixedLengthWithEvenEle.getMedian());
}

TEST_F(TestMedianOfFixedLengthArray, FindMediumAfterUpdate)
{
    medianOfFixedLengthWithOddEle.updateNum(9, 1);
    ASSERT_FLOAT_EQ(2, medianOfFixedLengthWithOddEle.getMedian());
    medianOfFixedLengthWithEvenEle.updateNum(-1, 4);
    ASSERT_FLOAT_EQ(5, medianOfFixedLengthWithEvenEle.getMedian());
}

TEST_F(TestMedianOfFixedLengthArray, FindMediumAfterAnotherInitialize)
{
    medianOfFixedLengthWithOddEle.initialize({-3, -1, 7});
    ASSERT_FLOAT_EQ(-1, medianOfFixedLengthWithOddEle.getMedian());
    medianOfFixedLengthWithEvenEle.initialize({1, 2, -5, 9, 2, 7});
    ASSERT_FLOAT_EQ(2, medianOfFixedLengthWithEvenEle.getMedian());
}